package Tests;

import static org.junit.Assert.*;
import org.junit.Test;

import example.AliveState;
import example.DeadState;
import framework.Board;
import framework.State;

/**
 * This class tests the framework.
 * 
 * Mainly tests for board.
 * 
 * If a board is initialized to be valid, and is valid after an update, then
 * inductively, the board will be valid at every step.
 * 
 * @author jtumarki, ntibrewa, shuaihan, wesleyk
 * 
 */

public class FwkTests {

	/**
	 * Tests constructor
	 */

	@Test(expected = IllegalArgumentException.class)
	public void constructorChecks1() {

		State[][] a = new State[5][5];
		Board b = new Board(0, -1, a);
	}

	/**
	 * Tests dimensions of board
	 */
	@Test(expected = IllegalArgumentException.class)
	public void constructorChecks2() {
		State d = new DeadState();
		State[][] a = { { d, d, d }, { d, d } };
		Board b = new Board(3, 2, a);
	}

	/**
	 * Tests out of bounds access
	 */
	@Test(expected = IllegalArgumentException.class)
	public void getStateCheck() {
		State d = new DeadState();
		State[][] a = { { d, d, d }, { d, d, d } };
		Board b = new Board(3, 2, a);
		b.getState(2, 1);
	}

	/**
	 * Setting a null state is not allowed
	 */
	@Test(expected = IllegalArgumentException.class)
	public void setStateCheck1() {
		State d = new DeadState();
		State[][] a = { { d, d, d }, { d, d, d } };
		Board b = new Board(3, 2, a);
		b.setState(null, 1, 1);
	}

	/**
	 * Setting a state and test for validity
	 */
	@Test
	public void setStateCheck2() {
		State d = new DeadState();
		State al = new AliveState();
		State[][] a = { { d, d, d }, { d, d, d } };
		Board b = new Board(3, 2, a);
		b.setState(al, 1, 2);
		State t = b.getState(1, 2);
		assertTrue(t instanceof AliveState);
		assertFalse(t instanceof DeadState);
	}
}
